﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.ShpMana
{
    public partial class wfDrivingLicense : msBsc.Cls.BPageHt
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void addDriving()
        {
            string djackId = this.GetParamHtValue("djackId");
            string documentNumber = this.GetParamHtValue("documentNumber");
            string documentPicture = this.GetParamHtValue("documentPicture");
            string name = this.GetParamHtValue("name");
            string gender = this.GetParamHtValue("gender");
            string nationId = this.GetParamHtValue("nationId");
            string nationName = this.GetParamHtValue("nationName");
            string countryId = this.GetParamHtValue("countryId");
            string countryName = this.GetParamHtValue("countryName");
            string cityId = this.GetParamHtValue("cityId");
            string cityName = this.GetParamHtValue("cityName");
            string destinationId = this.GetParamHtValue("destinationId");
            string destinationName = this.GetParamHtValue("destinationName");
            string birthDate = this.GetParamHtValue("birthDate");
            string issueDate = this.GetParamHtValue("issueDate");
            string quasiType = this.GetParamHtValue("quasiType");
            string effStartDate = this.GetParamHtValue("effStartDate");
            string ageLimit = this.GetParamHtValue("ageLimit");
            string publisherId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(publisherId))
            {
                this.ExecJScript("layer.alert('请登录！', 3);location.reload();");
            }
            if (string.IsNullOrEmpty(djackId)||string.IsNullOrEmpty(documentNumber)||string.IsNullOrEmpty(documentPicture)||string.IsNullOrEmpty(name)||string.IsNullOrEmpty(gender)||string.IsNullOrEmpty(nationId)||string.IsNullOrEmpty(nationName)||string.IsNullOrEmpty(countryId)||string.IsNullOrEmpty(countryName)||string.IsNullOrEmpty(cityId)||string.IsNullOrEmpty(cityName)||string.IsNullOrEmpty(destinationId)||string.IsNullOrEmpty(destinationName)||string.IsNullOrEmpty(birthDate)||string.IsNullOrEmpty(issueDate)||string.IsNullOrEmpty(quasiType)||string.IsNullOrEmpty(effStartDate)||string.IsNullOrEmpty(ageLimit))
            {
                this.ExecJScript("layer.alert('请完善驾照信息！', 3);");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizDrivingLicense drivingLicense = new AppLogic.DataAlc.CBizDrivingLicense())
            {
                //drivingLicense.AddDrivingLicense();
                using (msBsc.AppLogic.DataAlc.CBizSysFile oCBizSysFile = new msBsc.AppLogic.DataAlc.CBizSysFile())
                {
                    //保存到系统永久目录，之前上传时存到临时目录的，也可另写代码拷贝文件到其他目录
                    documentPicture = oCBizSysFile.SaveImgToServer(""
                        , msBsc.SvRef.UserInfo.Operator
                        , "1"
                        , "VEH"
                        , ""
                        , documentPicture//文件来源虚拟路径
                        , ""//文件来源物理路径，虚拟和物理只有一个就行
                        , true);
                }
                string strRet = drivingLicense.AddDrivingLicense(djackId,documentNumber,documentPicture,name,gender,nationId,nationName,countryId,countryName,cityId,cityName,destinationId,destinationName,birthDate,issueDate,quasiType,effStartDate,publisherId,ageLimit);// vehicleInfo.AddVehicle(djkId, vehicleName, buyTime, seats, price, serviceArea, vehicleType, vehicleBrand, vehicleColor, serviceType, picture, publisherId, vehicleNumber);
                if (strRet != "OK")
                {
                    this.ExecJScript("layer.alert('" + strRet + "', 3);");
                    return;
                }
                this.ExecJScript(@"success();");
            }
        }


        private void getArea2()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            string cityId = "";
            string destionId = "";
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selCity"",'" + cityId + "');");

                ds = cbcc.SelectCountryByParentId(cityId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "请选择";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selDestination"",'" + destionId + "');");
            }
        }
        private void getArea3()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            string destionId = "";
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "请选择";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selDestination"",'" + destionId + "');");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                getArea2();
            }
            else if (this.strAction == "addDriving")
            {
                addDriving();
            }
            else if (this.strAction == "upCountry")
            {
                getArea2();
            }
            else if (this.strAction == "upCity")
            {
                getArea3();
            }
        }
    }
}